package com.songshuai.webapi.jobapi.controller;



import com.songshuai.webapi.jobapi.dto.base.QueryResponse;
import com.songshuai.webapi.jobapi.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Api("学习中心")
@RestController
public class ScheduleController {

    @Autowired
    private CourseBindService courseBindService;

    @Autowired
    private SyncLogService syncLogService;

    @Autowired
    private CourseScheduleService courseScheduleService;

    @Autowired
    private SyncScheduleHisService scheduleHisService;

    @Autowired
    private SyncScheduleShiTingService scheduleShiTingService;

    @ApiOperation(value="课程绑定")
    @RequestMapping(value = "api/job/courseBind", method = RequestMethod.GET)
    public QueryResponse<Integer> courseBind(@RequestParam Boolean isFullDay,
                                             @RequestParam(required = false) String beginTime,
                                             @RequestParam(required = false) String endTime){
        if(isFullDay==null){
            isFullDay=false;
        }
        try{
            courseBindService.SyncNewYiXueCourse(isFullDay,beginTime,endTime);
        }catch (Exception ex){
            log.error("",ex);
        }
        return QueryResponse.setResData(0);
    }

    @ApiOperation(value="课程排课")
    @RequestMapping(value = "api/job/courseSchedule", method = RequestMethod.GET)
    public QueryResponse<Integer> courseSchedule(@RequestParam Boolean isFullDay,
                                                 @RequestParam(required = false) String beginTime,
                                                 @RequestParam(required = false) String endTime,
                                                 @RequestParam(required = false) Boolean isOnlySchedule){
        if(isFullDay==null){
            isFullDay=false;
        }
        courseScheduleService.SyncCourseSchedule(isFullDay,beginTime,endTime,isOnlySchedule);
        return QueryResponse.setResData(0);
    }

    @ApiOperation(value="试听排课")
    @RequestMapping(value = "api/job/shiTingSchedule", method = RequestMethod.GET)
    public QueryResponse<Integer> courseScheduleShiTing(@RequestParam Boolean isFullDay,
                                                        @RequestParam(required = false) String beginTime,
                                                        @RequestParam(required = false) String endTime,
                                                        @RequestParam(required = false) Boolean isOnlySchedule){
        if(isFullDay==null){
            isFullDay=false;
        }
        scheduleShiTingService.SycnCourseScheduleShiTing(isFullDay,beginTime,endTime,isOnlySchedule);
        return QueryResponse.setResData(0);
    }

    @ApiOperation(value="排课历史")
    @RequestMapping(value = "api/job/courseScheduleHis", method = RequestMethod.GET)
    public QueryResponse<Integer> courseScheduleHis(@RequestParam Boolean isFullDay,
                                                    @RequestParam(required = false) String beginTime,
                                                    @RequestParam(required = false) String endTime){
        if(isFullDay==null){
            isFullDay=false;
        }
        scheduleHisService.SyncCourseScheduleHis(isFullDay,beginTime,endTime);
        return QueryResponse.setResData(0);
    }

    @ApiOperation(value="根据lessonid 同步课表")
    @RequestMapping(value = "api/job/courseScheduleByIds", method = RequestMethod.POST)
    public QueryResponse<Integer> courseScheduleByIds(@RequestBody List<Integer>lessonIds){
        courseScheduleService.SyncScheduleByLessonIds(lessonIds);
        return QueryResponse.setResData(0);
    }

    @ApiOperation(value="根据lessonid 同步试听课表")
    @RequestMapping(value = "api/job/scheduleShiTingByIds", method = RequestMethod.POST)
    public QueryResponse<Integer> scheduleShiTingByIds(@RequestBody List<Integer>lessonIds){
        scheduleShiTingService.SyncScheduleByLessonIds(lessonIds);
        return QueryResponse.setResData(0);
    }

    @ApiOperation(value="根据lessonid 同步历史")
    @RequestMapping(value = "api/job/courseScheduleHisByLessonIds", method = RequestMethod.POST)
    public QueryResponse<Integer> courseScheduleHisByLessonIds(@RequestBody List<Integer>lessonIds){
        scheduleHisService.SyncScheduleHisByIds(lessonIds);
        return QueryResponse.setResData(0);
    }

    @ApiOperation(value="移除日志")
    @RequestMapping(value = "api/job/removeSyncLog", method = RequestMethod.GET)
    public QueryResponse<Integer> courseScheduleHis(@RequestParam String begin){
        Integer res=syncLogService.RemoveLogByDate(begin);
        return QueryResponse.setResData(res);
    }

    @ApiOperation(value="日志补偿")
    @RequestMapping(value = "api/job/syncLog", method = RequestMethod.GET)
    public QueryResponse<Integer> syncLog(@RequestParam(required = false)  String begin ){
        Integer res=syncLogService.syncLogs(begin);
        return QueryResponse.setResData(res);
    }
    
}
